<template>
  <view class="content">
    <view
      class="banner"
      style="
        background-image: url(../../static/stopCar/cp_bg1.png);
        background-size: 100% 100%;
      "
    >
      <text>特殊车牌</text>
      <text>大陆、港澳两地牌</text>
    </view>
    <view class="number-content">
      <text class="dialog-title">车牌号码</text>
      <u-input
        v-model="carNo"
        :type="type"
        :border="border"
        placeholderStyle="color: #999999;"
      />

      <u-button
        type="primary"
		:loading="loading"
        :custom-style="customStyle"
        @click="submitHandler"
        >确定</u-button
      >
      <view class="car-number" @click="Goback">
        <u-icon name="edit-pen-fill" size="32"></u-icon>
        <text>输入普通车牌</text>
        <u-icon name="arrow-right" size="20"></u-icon>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      keynumber: "",
      type: "text",
      border: true,
      customStyle: {
        fontSize: "32rpx",
        borderRadius: "16rpx",
        background: "#1677FE",
        margin: "0 55rpx",
        height: "100rpx",
      },
	  carNo:'',
	  loading:false
    };
  },
watch:{
	carNo:{
		handler(n){
			this.carNo=(n+'').toUpperCase()	
		},deep:true
	}
},
  methods: {
	  // 校验车牌
	  isVehicleNumber(vehicleNumber) {
      let result = false;
      const express =
        /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
      result = express.test(vehicleNumber);
      return result;
    },
    submitHandler() {
 
      const checked = this.isVehicleNumber(this.carNo);
      if (checked) {
        this.loading = true;
        let openid = uni.getStorageSync("userInfo").openid;
        this.$Api
          .getOrderByCarNo({
            openid,
            carNo: this.carNo,
          })
          .then((res) => {
            this.loading = false;
            uni.navigateTo({
              url:
                "../parkingPay/index?parkInfo=" +
                encodeURIComponent(JSON.stringify(res.data)),
            });
            this.cancelHandler();
          });
      } else {
        console.log("请输入正确的车牌号码");
        uni.showToast({
          title: "请输入正确的车牌号码",
          icon: "none",
        });
      }
    },
    Goback() {
		uni.navigateBack()
	},
  },
};
</script>

<style scoped lang="scss">
@import "index";
</style>
